package ch.exm.storm.functional.functions;

import ch.exm.storm.functional.matcher.Matcher;
import ch.exm.storm.introspection.IntrospectionUtil;

public class PropertyMatcher implements Matcher {
	
	private String propertyName;
	private Matcher propertyMatcher;
	
	public PropertyMatcher(String propertyName, Matcher propertyMatcher) {
		this.propertyName = propertyName; 
		this.propertyMatcher = propertyMatcher;
	}

	public boolean matches(Object item) {
		Object value = IntrospectionUtil.call(item, propertyName);
		return propertyMatcher.matches(value);
	}

	public static PropertyMatcher with(String propertyName, Matcher propertyMatcher) {
		return new PropertyMatcher(propertyName, propertyMatcher);
	}
}
